package cn.lklink.pay.lkl.request.v3.los;

import cn.lklink.pay.lkl.core.LakalaPayConfig;
import cn.lklink.pay.lkl.request.ReqData;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.List;

/**
 * 收银台下单请求报文
 * 交易接口V3.0下订单类接口
 *
 * @author Mr丶xie
 * @version 1.0.0
 * @mail xielinke@lklink.cn
 */
public class GenerateOrderRequest extends ReqData {

    private GenerateOrderRequest() {
    }

    /**
     * 初始化收银台下单接口请求报文
     *
     * @param out_order_no 商户订单号
     * @param total_amount 订单金额，单位：分
     * @param order_info   订单标题，在使用收银台扫码支付时必输入
     */
    public GenerateOrderRequest(String out_order_no, Long total_amount, String order_info) {
        this.out_order_no = out_order_no;
        this.merchant_no = LakalaPayConfig.MERCHANT_NO;
        this.channel_id = LakalaPayConfig.CHANNEL_ID;
        this.total_amount = total_amount;
        this.order_efficient_time = orderEfficientTime(10);
        this.order_info = order_info;
    }

    /**
     * 商户订单号
     */
    private String out_order_no;

    /**
     * 商户号
     */
    private String merchant_no;

    /**
     * 交易设备标识（非合单场景必输该字段），进件返回接口中的termId字段，非API接口进件请联系业务员
     */
    private String vpos_id;

    /**
     * 渠道号 （用于接收订单通知报文，拉卡拉开通）
     */
    private String channel_id;

    /**
     * 业务模式： ACQ-收单 不填，默认为“ACQ-收单”
     */
    private String busi_mode;

    /**
     * 订单金额，单位：分
     */
    private Long total_amount;

    /**
     * 订单有效期 格式yyyyMMddHHmmss,最大支持下单时间+2天
     */
    private String order_efficient_time;

    /**
     * 订单支付成功后商户接收订单通知的地址
     */
    private String notify_url;

    /**
     * 是否支持撤销 默认 0 不支持
     * busi_mode为“PAY-付款”不支持 撤销
     */
    private Integer support_cancel;

    /**
     * 是否支持退款 默认0 不支持
     */
    private Integer support_refund;

    /**
     * 是否支持“多次发起支付” 默认0 不支持
     */
    private Integer support_repeat_pay;

    /**
     * 	业务类型控制参数，jsonStr格式
     */
    private String busi_type_param;

    /**
     * 发起订单方的userId，归属于channelId下的userId
     */
    private String out_user_id;

    /**
     * 客户端下单完成支付后返回的商户网页跳转地址。
     */
    private String callback_url;

    /**
     * 订单标题，在使用收银台扫码支付时必输入，交易时送往账户端
     */
    private String order_info;

    /**
     * 	结算终端号,合单场景必输该字段
     */
    private String term_no;

    /**
     * 	合单标识，“1”为合单，不填默认是为非合单
     */
    private String split_mark;

    /**
     * 	拆单信息
     * 合单标识为“1”时必传该字段。,详细字段见out_split_info字段说明
     */
    private List<OutSplitInfoRequest> out_split_info;

    /**
     * 收银台样式（STD-标准收银台、FSWY - 福斯网银、FSZZ - 福斯转账、B2B-B2B收银台
     */
    private String page_style;

    /**
     * 结算类型（非合单） （“0”或者空，常规结算方式） 注意：该字段会影响结算方式，慎用。
     */
    private String settle_type;

    public String getOut_order_no() {
        return out_order_no;
    }

    public void setOut_order_no(String out_order_no) {
        this.out_order_no = out_order_no;
    }

    public String getMerchant_no() {
        return merchant_no;
    }

    public void setMerchant_no(String merchant_no) {
        this.merchant_no = merchant_no;
    }

    public String getVpos_id() {
        return vpos_id;
    }

    public void setVpos_id(String vpos_id) {
        this.vpos_id = vpos_id;
    }

    public String getChannel_id() {
        return channel_id;
    }

    public void setChannel_id(String channel_id) {
        this.channel_id = channel_id;
    }

    public String getBusi_mode() {
        return busi_mode;
    }

    public void setBusi_mode(String busi_mode) {
        this.busi_mode = busi_mode;
    }

    public Long getTotal_amount() {
        return total_amount;
    }

    public void setTotal_amount(Long total_amount) {
        this.total_amount = total_amount;
    }

    public String getOrder_efficient_time() {
        return order_efficient_time;
    }

    public void setOrder_efficient_time(String order_efficient_time) {
        this.order_efficient_time = order_efficient_time;
    }

    public String getNotify_url() {
        return notify_url;
    }

    public void setNotify_url(String notify_url) {
        this.notify_url = notify_url;
    }

    public Integer getSupport_cancel() {
        return support_cancel;
    }

    public void setSupport_cancel(Integer support_cancel) {
        this.support_cancel = support_cancel;
    }

    public Integer getSupport_refund() {
        return support_refund;
    }

    public void setSupport_refund(Integer support_refund) {
        this.support_refund = support_refund;
    }

    public Integer getSupport_repeat_pay() {
        return support_repeat_pay;
    }

    public void setSupport_repeat_pay(Integer support_repeat_pay) {
        this.support_repeat_pay = support_repeat_pay;
    }

    public String getBusi_type_param() {
        return busi_type_param;
    }

    public void setBusi_type_param(String busi_type_param) {
        this.busi_type_param = busi_type_param;
    }

    public String getOut_user_id() {
        return out_user_id;
    }

    public void setOut_user_id(String out_user_id) {
        this.out_user_id = out_user_id;
    }

    public String getCallback_url() {
        return callback_url;
    }

    public void setCallback_url(String callback_url) {
        this.callback_url = callback_url;
    }

    public String getOrder_info() {
        return order_info;
    }

    public void setOrder_info(String order_info) {
        this.order_info = order_info;
    }

    public String getTerm_no() {
        return term_no;
    }

    public void setTerm_no(String term_no) {
        this.term_no = term_no;
    }

    public String getSplit_mark() {
        return split_mark;
    }

    public void setSplit_mark(String split_mark) {
        this.split_mark = split_mark;
    }

    public List<OutSplitInfoRequest> getOut_split_info() {
        return out_split_info;
    }

    public void setOut_split_info(List<OutSplitInfoRequest> out_split_info) {
        this.out_split_info = out_split_info;
    }

    public String getPage_style() {
        return page_style;
    }

    public void setPage_style(String page_style) {
        this.page_style = page_style;
    }

    public String getSettle_type() {
        return settle_type;
    }

    public void setSettle_type(String settle_type) {
        this.settle_type = settle_type;
    }

    private String orderEfficientTime(int minutes) {
        LocalDateTime date = LocalDateTime.now();
        DateTimeFormatter format1 = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
        LocalDateTime nextWeek = date.minus(-minutes, ChronoUnit.MINUTES);//20分钟后
        return nextWeek.format(format1);
    }
}
